package com.leo.Other;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 三个线程ABC
 * @author xuexiaolei
 * @version 2018年03月13日
 */
public class MultiThreadABC {
    private static AtomicInteger a = new AtomicInteger(0);
    public static void main(String[] args) {
        ExecutorService exec = Executors.newFixedThreadPool(3);
        exec.submit(new PrintTask(0, "A"));
        exec.submit(new PrintTask(1, "B"));
        exec.submit(new PrintTask(2, "C"));
        exec.shutdown();
    }
    static class PrintTask implements Runnable{
        int anInt;
        String label;
        public PrintTask(int anInt, String label) {
            this.anInt = anInt;
            this.label = label;
        }

        @Override public void run() {
            while (a.get() < 30){
                if (a.get() % 3 == anInt){
                    System.out.println(label);
                    a.incrementAndGet();
                }
            }
        }
    }
}
